home *** CD-ROM | disk | FTP | other *** search
/ Maximum CD 2000 March / maximum-cd-2000-03.iso / Quake3 Game Source / Q3AGameSource.exe / Main / cg_consolecmds.c < prev    next >
Encoding:
C/C++ Source or Header  |  2000-01-18  |  4.6 KB  |  208 lines

  1. // Copyright (C) 1999-2000 Id Software, Inc.
  2. //
  3. // cg_consolecmds.c -- text commands typed in at the local console, or
  4. // executed by a key binding
  5.  
  6. #include "cg_local.h"
  7.  
  8.  
  9.  
  10. void CG_TargetCommand_f( void ) {
  11.     int        targetNum;
  12.     char    test[4];
  13.  
  14.     targetNum = CG_CrosshairPlayer();
  15.     if (!targetNum ) {
  16.         return;
  17.     }
  18.  
  19.     trap_Argv( 1, test, 4 );
  20.     trap_SendConsoleCommand( va( "gc %i %i", targetNum, atoi( test ) ) );
  21. }
  22.  
  23.  
  24.  
  25. /*
  26. =================
  27. CG_SizeUp_f
  28.  
  29. Keybinding command
  30. =================
  31. */
  32. static void CG_SizeUp_f (void) {
  33.     trap_Cvar_Set("cg_viewsize", va("%i",(int)(cg_viewsize.integer+10)));
  34. }
  35.  
  36.  
  37. /*
  38. =================
  39. CG_SizeDown_f
  40.  
  41. Keybinding command
  42. =================
  43. */
  44. static void CG_SizeDown_f (void) {
  45.     trap_Cvar_Set("cg_viewsize", va("%i",(int)(cg_viewsize.integer-10)));
  46. }
  47.  
  48.  
  49. /*
  50. =============
  51. CG_Viewpos_f
  52.  
  53. Debugging command to print the current position
  54. =============
  55. */
  56. static void CG_Viewpos_f (void) {
  57.     CG_Printf ("(%i %i %i) : %i\n", (int)cg.refdef.vieworg[0],
  58.         (int)cg.refdef.vieworg[1], (int)cg.refdef.vieworg[2], 
  59.         (int)cg.refdefViewAngles[YAW]);
  60. }
  61.  
  62.  
  63. static void CG_ScoresDown_f( void ) {
  64.     if ( cg.scoresRequestTime + 2000 < cg.time ) {
  65.         // the scores are more than two seconds out of data,
  66.         // so request new ones
  67.         cg.scoresRequestTime = cg.time;
  68.         trap_SendClientCommand( "score" );
  69.  
  70.         // leave the current scores up if they were already
  71.         // displayed, but if this is the first hit, clear them out
  72.         if ( !cg.showScores ) {
  73.             cg.showScores = qtrue;
  74.             cg.numScores = 0;
  75.         }
  76.     } else {
  77.         // show the cached contents even if they just pressed if it
  78.         // is within two seconds
  79.         cg.showScores = qtrue;
  80.     }
  81. }
  82.  
  83. static void CG_ScoresUp_f( void ) {
  84.     cg.showScores = qfalse;
  85.     cg.scoreFadeTime = cg.time;
  86. }
  87.  
  88. static void CG_TellTarget_f( void ) {
  89.     int        clientNum;
  90.     char    command[128];
  91.     char    message[128];
  92.  
  93.     clientNum = CG_CrosshairPlayer();
  94.     if ( clientNum == -1 ) {
  95.         return;
  96.     }
  97.  
  98.     trap_Args( message, 128 );
  99.     Com_sprintf( command, 128, "tell %i %s", clientNum, message );
  100.     trap_SendClientCommand( command );
  101. }
  102.  
  103. static void CG_TellAttacker_f( void ) {
  104.     int        clientNum;
  105.     char    command[128];
  106.     char    message[128];
  107.  
  108.     clientNum = CG_LastAttacker();
  109.     if ( clientNum == -1 ) {
  110.         return;
  111.     }
  112.  
  113.     trap_Args( message, 128 );
  114.     Com_sprintf( command, 128, "tell %i %s", clientNum, message );
  115.     trap_SendClientCommand( command );
  116. }
  117.  
  118.  
  119. typedef struct {
  120.     char    *cmd;
  121.     void    (*function)(void);
  122. } consoleCommand_t;
  123.  
  124. static consoleCommand_t    commands[] = {
  125.     { "testgun", CG_TestGun_f },
  126.     { "testmodel", CG_TestModel_f },
  127.     { "nextframe", CG_TestModelNextFrame_f },
  128.     { "prevframe", CG_TestModelPrevFrame_f },
  129.     { "nextskin", CG_TestModelNextSkin_f },
  130.     { "prevskin", CG_TestModelPrevSkin_f },
  131.     { "viewpos", CG_Viewpos_f },
  132.     { "+scores", CG_ScoresDown_f },
  133.     { "-scores", CG_ScoresUp_f },
  134.     { "+zoom", CG_ZoomDown_f },
  135.     { "-zoom", CG_ZoomUp_f },
  136.     { "sizeup", CG_SizeUp_f },
  137.     { "sizedown", CG_SizeDown_f },
  138.     { "weapnext", CG_NextWeapon_f },
  139.     { "weapprev", CG_PrevWeapon_f },
  140.     { "weapon", CG_Weapon_f },
  141.     { "tell_target", CG_TellTarget_f },
  142.     { "tell_attacker", CG_TellAttacker_f },
  143.     { "tcmd", CG_TargetCommand_f },
  144.     { "loaddefered", CG_LoadDeferredPlayers }    // spelled wrong, but not changing for demo...
  145. };
  146.  
  147.  
  148. /*
  149. =================
  150. CG_ConsoleCommand
  151.  
  152. The string has been tokenized and can be retrieved with
  153. Cmd_Argc() / Cmd_Argv()
  154. =================
  155. */
  156. qboolean CG_ConsoleCommand( void ) {
  157.     const char    *cmd;
  158.     int        i;
  159.  
  160.     cmd = CG_Argv(0);
  161.  
  162.     for ( i = 0 ; i < sizeof( commands ) / sizeof( commands[0] ) ; i++ ) {
  163.         if ( !Q_stricmp( cmd, commands[i].cmd ) ) {
  164.             commands[i].function();
  165.             return qtrue;
  166.         }
  167.     }
  168.  
  169.     return qfalse;
  170. }
  171.  
  172.  
  173. /*
  174. =================
  175. CG_InitConsoleCommands
  176.  
  177. Let the client system know about all of our commands
  178. so it can perform tab completion
  179. =================
  180. */
  181. void CG_InitConsoleCommands( void ) {
  182.     int        i;
  183.  
  184.     for ( i = 0 ; i < sizeof( commands ) / sizeof( commands[0] ) ; i++ ) {
  185.         trap_AddCommand( commands[i].cmd );
  186.     }
  187.  
  188.     //
  189.     // the game server will interpret these commands, which will be automatically
  190.     // forwarded to the server after they are not recognized locally
  191.     //
  192.     trap_AddCommand ("kill");
  193.     trap_AddCommand ("say");
  194.     trap_AddCommand ("say_team");
  195.     trap_AddCommand ("give");
  196.     trap_AddCommand ("god");
  197.     trap_AddCommand ("notarget");
  198.     trap_AddCommand ("noclip");
  199.     trap_AddCommand ("team");
  200.     trap_AddCommand ("follow");
  201.     trap_AddCommand ("levelshot");
  202.     trap_AddCommand ("addbot");
  203.     trap_AddCommand ("setviewpos");
  204.     trap_AddCommand ("vote");
  205.     trap_AddCommand ("callvote");
  206.     trap_AddCommand ("loaddefered");    // spelled wrong, but not changing for demo
  207. }
  208.